# @Time:2021/6/10 19:03
# @Author:5120195554王欣霏
# -*- coding = utf-8 -*-

import os
import sys
import pygame
from pygame.constants import QUIT

pygame.init()
back_img_path1 = os.path.join('../resource', 'img', 'village.jpg')
back_img_path2 = os.path.join('../resource', 'img', 'temple.jpg')
back_surface1 = pygame.image.load(back_img_path1)
back_surface2 = pygame.image.load(back_img_path2)
screen = pygame.display.set_mode((800, 600), 0, 32)
pygame.display.set_caption("场景变换")

alpha = 0
first = True
while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

    if first:  # 第一张图慢慢变淡
        back_surface1.set_alpha(255 - alpha)
    else:  # 第二张图慢慢变深
        back_surface2.set_alpha(alpha)
    screen.fill((0, 0, 0))
    if first:
        screen.blit(back_surface1, (0, 0))
    else:
        screen.blit(back_surface2, (0, 0))
    pygame.time.delay(10)
    alpha += 1
    if alpha == 255:
        alpha = 1
        first = not first
    pygame.display.update()
